package com.bana.fvs.controller;

import com.bana.sys.code.DatabaseResult;
import com.bana.fvs.code.ProgramStatus;
import com.bana.fvs.dao.ProgramDAO;
import com.bana.fvs.model.Program;
import com.bana.fvs.service.ProgramService;
import com.bana.sys.utils.ActionResult;
import com.bana.sys.utils.TokenRequest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 雾区方案
 */
@RestController
@RequestMapping(value = "/program", method = RequestMethod.POST)
public class ProgramController {

    @Resource
    private ProgramDAO programDAO;

    @Resource
    private ProgramService programService;


    /**
     * 查询方案集合
     *
     * @param request 分页
     * @return 方案集合
     */
    @RequestMapping(value = "/getPrograms.do", method = RequestMethod.POST)
    public List<Program> getPrograms(@RequestBody TokenRequest<Program> request) {
        return  programDAO.getPrograms(request.getData().getWqbm(), ProgramStatus.All);
    }

    /**
     * 新增重复方案
     *
     * @param request 重复方案
     * @return 操作结果
     */
    @RequestMapping(value = "/insertProgram.do", method = RequestMethod.POST)
    public ActionResult insertProgram(@RequestBody TokenRequest<Program> request) {
        ActionResult actionResult = new ActionResult();
        programDAO.insertProgram(request.getData());
        actionResult.setCzjg(DatabaseResult.Success);
        actionResult.setKey(request.getData().getFabm());
        return actionResult;
    }

    /**
     * 修改重复方案
     *
     * @param request 重复方案
     * @return 操作结果
     */
    @RequestMapping(value = "/updateProgram.do", method = RequestMethod.POST)
    public ActionResult updateProgram(@RequestBody TokenRequest<Program> request) {
        ActionResult actionResult = new ActionResult();
        programDAO.updateProgram(request.getData());
        actionResult.setCzjg(DatabaseResult.Success);
        return actionResult;
    }


    /**
     * 删除重复方案
     *
     * @param request 重复方案
     * @return 操作结果
     */
    @RequestMapping(value = "/deleteProgram.do", method = RequestMethod.POST)
    public ActionResult deleteProgram(@RequestBody TokenRequest<Program> request) {
        ActionResult actionResult = new ActionResult();
        programDAO.deleteProgram(request.getData().getFabm());
        actionResult.setCzjg(DatabaseResult.Success);
        return actionResult;
    }


    /**
     * 修改雾区固定方案使用状态
     * @param request 方案集合
     * @return 操作结果
     */
    @RequestMapping(value = "/updateProgramsStatus.do",method = RequestMethod.POST)
    public ActionResult updateProgramsStatus(@RequestBody TokenRequest<List<Program>> request){
        ActionResult actionResult = new ActionResult();
        programService.updateStatus(request.getData());
        actionResult.setCzjg(DatabaseResult.Success);
        return actionResult;
    }


}
